<%@page import="java.text.DecimalFormat"%>
<%@ page language="java" import="java.util.*" import="com.rw.table.Cart" import="com.rw.table.Address" 
	import="java.util.List" import="com.rw.table.Item" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'order_confirm.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<style type="text/css">
@import "./css/shop/header.css";

@import "./css/shop/order_confirm.css";
</style>


<script language="javascript" type="text/javascript"
	src="javascript/MulitiEffect.js">
	</script>
	<script type="text/javascript">

 function submitOrder()
 {

   alert("订单提交成功");
   document.forms("itemForm").submit();

 }
 function listUserAds()
 {
	 document.forms("listUserAds").submit();
 }

</script>
</head>

<body>
	<jsp:include flush="true" page="header.jsp"></jsp:include>
	<form method="post" id="listUserAds" action="listUserAdsAction">
		<input id="isFromOrder" type="hidden" name="isFromOrder" value="true" />
	</form>
	<% int t = 0;
	if(request.getAttribute("cartInfoList")!=null){
   List<Cart> cartList = (List<Cart>)request.getAttribute("cartInfoList");
   List<Item> itemList = (List<Item>)request.getAttribute("cartItemList");
   List<Address> addressList = (List<Address>)request.getAttribute("addressList");
   //分页信息
   int totalPageNum = (Integer)request.getAttribute("totalPageNum");
   int nowPage = (Integer)request.getAttribute("nowPage");
   long userId = (Long)request.getAttribute("userId");
   //商品信息
   int userScore = (Integer)request.getAttribute("score");
   int percent = (Integer)request.getAttribute("percent");
   String errorMsg = (String)request.getAttribute("errorMsg");
   Float totalPrice = new Float(0);
   
   Iterator<Cart> iterator = cartList.iterator();
   Iterator<Item> iterator2 = itemList.iterator();
   Iterator<Address> iterator3 = addressList.iterator();
   %>
	<div class="order-confirm-Frame">
		<form id="itemForm" method="post" action="submitOrderAction">
			<div class="order-confirm-List">
				<h3>商品清单</h3>&nbsp;<% if(errorMsg!=null){%><h3><span class="red"><%=errorMsg %></span></h3><% }%>

				<table class="itemTable" border="0" cellpadding="8">
					<tr class="title">
					  
						<td align="center" width="100px">商品名</td>
						<td align="center" width="100px">市场价</td>
						<td align="center" width="100px">会员价</td>
						<td align="center" width="100px">为您节省</td>
						<td align="center" width="100px">数量</td>

					</tr>
					<% if (cartList!=null&&itemList!=null){ 
						
     while(iterator.hasNext()){
	   Cart cart = iterator.next();
	   Item item = iterator2.next();
	   DecimalFormat df = new DecimalFormat("#0.00");
	   long cartId=cart.getCartId();
	      int pageSize = (Integer)request.getAttribute("pageSize");
	      long itemId = cart.getCartItemId();	
	          float marketPrice = item.getItemMarketPrice();
			float priceAfterDiscount = item.getItemMarketPrice()*item.getItemdiscount();
			float save = item.getItemMarketPrice()-(item.getItemMarketPrice()*item.getItemdiscount());
			%>
					<tr>
				
						<td align="center" width="100px"><%=item.getItemName() %></td>
						<td align="center" width="100px"><%=df.format(marketPrice) %></td>
						<td align="center" width="100px"><%=df.format(priceAfterDiscount) %></td>
						<td align="center" width="100px"><%=df.format(save)%></td>
						<td align="center" width="100px"><%=cart.getCartItemNum() %></td>
					</tr>
					<%float temp = item.getItemMarketPrice()*item.getItemdiscount()*cart.getCartItemNum();
					totalPrice = totalPrice+temp;
       }
	}
					DecimalFormat df = new DecimalFormat("#0.00");
					int score = (totalPrice.intValue())/10;
					float finalPrice =totalPrice*percent/100+10;
					String totalShow = df.format(totalPrice);
					String finalShow = df.format(finalPrice);
					%>
					</table>
					<br>
					<table align="center">
					<tr>
						<td align="center" width="100px"><span class="red">商品总价</span></td>
						<td align="center" width="100px">运费</td>
						<td align="center" width="100px">本单将产生积分</td>
						<td align="center" width="100px">积分折扣</td>
						<td align="center" width="100px"><span class="red">您有<%=userScore %>个积分</span></td>
						<td align="center" width="100px">订单总价</td>
						<td>返回购物车</td>
					</tr>
					<tr>
						<td align="center">￥<%=totalShow %></td>
						<td align="center">￥10</td>
						<td align="center"><span class="red"><%=score %></span></td>
						<td align="center"><%=percent %>%</td>
						<td align="center"></td>
						<td align="center">￥<%=finalShow %></td>
						<td><a  href="listCartItemsAction"><img src="images/src/bg/cart.png" alt="返回购物车"/></a></td>
					</tr>
				</table>

			</div>

			<div class="ReceiveAddress">
				<h3>
					送货地址 <input type="button" border="2" value="修改"
						onclick="listUserAds()" />
				</h3>
				<table class="ReceiveAddress" cellpadding="3">
				<% int s = 0;
				   while(iterator3.hasNext()) {
				    Address addressInfo = iterator3.next();%>
				    
					<tr>
					    <td align="center" width="70px"><input type="radio" name="orderAddId" value="<%=addressInfo.getAddressId() %>"
					    <%if(s==0){
					    	%>checked<%
					    }
					    %>/></td>
						<td align="center" width="70px">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:</td>
						<td align="left" width="90px"><%=addressInfo.getAddressReceiver() %></td>
					    
						<td align="center" width="70px">通讯地址:</td>
						<td align="left" width="200px"><%=addressInfo.getAddressDetail() %></td>
						<td align="center" width="70px">手机号码:</td>
						<td align="left" width="90px"><%=addressInfo.getAddressPhone() %></td>

					</tr>
                 <%s++;
                 } %>
					<tr>
					    <td></td>
						<td>支付方式:</td>
						<td>货到付款</td>
						<td></td>
						<td><%if(addressList.isEmpty()){ %>你还未填写地址信息</td>
						<td>请点击修改</td>
						<td><span class="red">请仔细核查信息，确定无误后： </span> <%} %></td>
							<td><%if(!addressList.isEmpty()){ %>
							<input type="hidden" name="orderUserId" value="<%=userId%>"/>
							<input type="hidden" name="orderTotalPrice" value="<%=finalPrice%>"/>
							<input type="hidden" name="score" value="<%=score %>"/>
							<input type="button" value="提交订单" onClick="submitOrder()"><%} %></td>
					</tr>

				</table>
			</div>
		</form>
		<% }else{%><a>您的购物车为空</a><%} %>
	</div>


	<jsp:include page="footer.jsp" flush="true"></jsp:include>
</body>
</html>
